﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.Contracts;
using CMS.Model;
using CMSWCSFSolution.CMS.Interface.Services;
using CMS.Channel;


namespace CMSWCSFSolution.CMS.Services
{
    public class CMSService : ICMSService
    {

        public List<Student> GetAllstudents(int pageIndex, int pageSize, out int rowCount)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllStudents(pageIndex, pageSize, out rowCount);
        }
        public List<Grade> GetAllGrades()
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllGrades();
        }

        public Student GetStudentById(int studentId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetStudentById(studentId);
        }
        public void AddStudent(Student student)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.AddStudent(student);
        }
        public void UpdateStudent(Student student)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.UpdateStudent(student);
        }
        public void DeleteStudentById(int studentId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.DeleteStudentById(studentId);
        }
        public List<Teacher> GetAllTeachers(int pageIndex, int pageSize, out int rowCount)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllTeachers(pageIndex, pageSize, out rowCount);

        }
        public List<Teacher> GetTeacherById(int teacherId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetTeacherById(teacherId);
        }
        public void AddTeacher(Teacher teacher)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.AddTeacher(teacher);
        }
        public void DeleteTeacherById(int teacherId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.DeleteTeacherById(teacherId);
        }
        public List<Department> GetAllDepartments()
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllDepartments();
        }
        public List<Department> GetDepartmentById(int departmentId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetDepartmentById(departmentId);
        }

        public void UpdateTeacher(Teacher teacher)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.UpdateTeacher(teacher);
        }

        /// <summary>
        /// Gets Courses Based on Condition
        /// Created by Fiona
        /// </summary>
        /// <param name="courseName">string CourseName</param>
        /// <param name="courseStatus">string CourseStatus</param>
        /// <param name="pageIndex">int Current Page</param>
        /// <param name="pageSize">int Page Size</param>
        /// <param name="rowCount">out int All Records Count</param>
        /// <returns></returns>
        public List<Course> GetCoursesByCondition(string courseName, string courseStatus, int pageIndex, int pageSize, out int rowCount)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetCoursesByCondition(courseName, courseStatus, pageIndex, pageSize, out rowCount);
        }

        /// <summary>
        /// Deletes Course By CourseId
        /// Created by Fiona
        /// </summary>
        /// <param name="courseId">int CourseId</param>
        public void DeleteCourseById(int courseId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.DeleteCourseById(courseId);
        }

        /// <summary>
        /// Changes Courses Status
        /// Created by Fiona
        /// </summary>
        /// <param name="inputCourse">Course Object</param>
        public void ChangeCourseStatus(Course inputCourse)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.ChangeCourseStatus(inputCourse);
        }

        /// <summary>
        /// Generates Course Report
        /// Created by Fiona
        /// </summary>
        /// <param name="condition">Condition Object</param>
        /// <param name="pageIndex">int Current Page</param>
        /// <param name="pageSize">int Page Size</param>
        /// <param name="rowCount">out int All Row Records</param>
        /// <returns></returns>
        public List<CourseList> GenerateCourseReport(Condition condition, int pageIndex, int pageSize, out int rowCount)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GenerateCourseReport(condition, pageIndex, pageSize, out rowCount);
        }

        public List<Teacher> GetAllTeacher()
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllTeacher();
        }
        public List<Level> GetAllLevels()
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetAllLevels();
        }
        public List<Student> GetStudentsInCourse(int courseId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetStudentsInCourse(courseId);
        }
        public List<Student> GetStudentsNotInCourse(int courseId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetStudentsNotInCourse(courseId);
        }
        public void AddCourseDetail(CourseDetails courseDetail)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.AddCourseDetail(courseDetail);
        }
        public void UpdateCourse(Course course)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.UpdateCourse(course);
        }
        public void DeleteAllStudentsByCourseId(int courseId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            iProjectBService.DeleteAllStudentsByCourseId(courseId);
        }
        public int AddCourse(Course course)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.AddCourse(course);
        }
        public List<Course> GetCourseById(int courseId)
        {
            CMSChannel channel = new CMSChannel();
            IProjectBService iProjectBService = channel.CreateChannel();
            return iProjectBService.GetCourseById(courseId);
        }
    }

}
